package com.example.laixunlong.control;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.example.laixunlong.R;

public class PopupWindow_tanchuang extends AppCompatActivity
{
    PopupWindow tanchuang;
    View view;
    Button but,but2;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popupwindow_tanchuang);
        /*创建并引入布局*/
        view = getLayoutInflater().inflate(R.layout.z_tanchuang,null);
        /*窗体初始化 :   布局 , 宽 , 高 , 是否开启点击空白处关闭*/
        tanchuang= new PopupWindow(view, 600, 300, true);
        but=view.findViewById(R.id.button_1);
        but2=view.findViewById(R.id.button_2);
    }
    public void appear_window(View v)
    {
        tanchuang.setBackgroundDrawable(ContextCompat.getDrawable(this,R.drawable.yqqs));/*设置背景*/
        tanchuang.showAsDropDown(view,100,-100);//出现位置,单位dp
        //窗体内按钮
        but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e("弹窗按钮", "弹窗按钮被点击了" );
            }
        });
        but2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tanchuang.dismiss();
            }
        });
    }

}
